<?php
/**
我的服务订单
 */

namespace App\Http\Controllers\Property;


use App\Common\json;
use App\Common\SmsClient;
use App\Http\Controllers\Controller;
use App\Libraries\upload;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class ServiceOrderController extends Controller{

    public function ServiceOrder(Request $request){
        if($request ->isMethod('post')){
            $arr  = (object)array();
            $repair_id       = $request ->input('repair_id');
            $data            = DB::table('repair')
                             ->leftjoin('user','repair.user_repair','=','user.user_id')
                             ->leftjoin('village','user.user_village','=','village.village_id')
                             ->leftjoin('repair_type','repair.repair_id','=','repair_type.repairtype_repair')
                             ->leftjoin('hashslinger','repair.repair_hashslinger','=','hashslinger.hashslinger_id')
                             ->where('repair_id',$repair_id)
                             ->get();
            foreach ($data as $value){

                $villagename    = $value ->village_name;
                $user_roomname  = $value ->user_roomname;
/*                $floor          = $value ->floor;
                $number         = $value ->number;
                $room           = $value ->room;*/
                if(empty($value ->repair_image)){
                    $repair_image  = [];
                }else {
                    $repair_image = $value->repair_image;
                }
                $name         = $value ->name;
                $ha_phone        = $value ->hashslinger_phone;
                $wtbznr          = $value->wtbznr;
                $address        = $villagename.'-'.$user_roomname;
                $da             = array(
                    'order'=>$value->repair_id,
                    'repair_create_time'=>$value->repair_create_time,
                    'status'=>$value->status,
                    'phone'=>$value->phone,
                    'nickname'=>$value->nickname,
                    'address'=>$address,
                    'repair_image' =>$repair_image,
                    'name' =>$name,
                    'hashslinger_phone'=>$ha_phone,
                    'wtbznr'            =>$wtbznr,
                    'depict' =>$value->depict,
                    'content'=>$value->content,
                    'quality'=>$value->quality,
                    'speed' =>$value->speed);
            }
            if($data == true){
                return json::json('success', '获取全部数据成功', $da);
            }else{
                return json::json('failure','由于网络或者不正当原因失败',$arr);
            }
        }else{
            return json::json('101','提交方式错误','');
        }
    }

    //发布评论
    public function PostComment(Request $request){
        if($request ->isMethod('post')){
            $arr             = (object)array();
            $repair_id       = $request ->input('repair_id');
            $content         = $request ->input('content');
            $quality         = $request ->input('quality');
            $speed           = $request ->input('speed');
            $select          = DB::table('repair')
                             ->where('repair_id',$repair_id)
                             ->where('status',2)
                             ->get();
            if($select == true){
            $data            = DB::table('repair')
                             ->where('repair_id',$repair_id)
                             ->update([
                                 'content'    =>$content,
                                 'quality'    =>$quality,
                                 'speed'      =>$speed,
                                 'status'     =>3
                             ]);
            if($data == true){
                return json::json('success', '评论成功', $arr);
            }else{
                return json::json('failure','由于网络或者不正当原因失败',$arr);
            }
            }else{
                return json::json('failure','由于网络或者不正当原因失败',$arr);
            }
        }else{
            return json::json('101','提交方式错误','');
        }
    }

    public function clickServiceOrder(Request $request){
        $arr             = (object)array();
        if($request ->isMethod('post')){
            $repair_id       = $request ->input('repair_id');
            $update          = DB::table('repair') ->where('repair_id',$repair_id)
                             ->update(['status'=>2]);
            if($update == true){
                return json::json('success', '通过用户确认', $arr);
            }else{
                return json::json('failure','网络太慢请等待',$arr);
            }

        }
    }




}